package cn.lastcc.recover.contacts.android.services;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import cn.lastcc.recover.contacts.android.utils.Constants;
import cn.lastcc.recover.contacts.android.utils.ServiceUtil;

public class RecoverBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(Constants.TAG, "RecoverBroadcastReceiver#onReceive is entry.");
        boolean isRunning = ServiceUtil.isServiceRun(context, RecoverService.class.getName());
        String action = intent.getAction();
//        if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
//            if (!isRunning) {
//                 Intent services = new Intent(context, RecoverService.class);
//                services.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                context.startService(services);
//            }
//            Log.i(Constants.TAG, "RecoverService is started -- Started.");
//        }
        if (Constants.BROADCAST_RECEIVER_MSG_START.equalsIgnoreCase(action)) {
            if (!isRunning) {
                context.startService(new Intent(context, RecoverService.class));
            }
            Log.i(Constants.TAG, "RecoverService is started.");
        } else if (Constants.BROADCAST_RECEIVER_MSG_STOP.equalsIgnoreCase(action)) {
            if (isRunning) {
                context.stopService(new Intent(context, RecoverService.class));
            }
            Log.i(Constants.TAG, "RecoverService is stoped.");
        }
        Log.d(Constants.TAG, "RecoverBroadcastReceiver#onReceive is exit.");
    }

}
